package com.ev.apis.controller.hr;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.ev.custom.vo.ClientEntity;
import com.ev.framework.annotation.EvApiByToken;
import com.ev.framework.il8n.MessageSourceHandler;
import com.ev.framework.utils.BeanUtils;
import com.ev.framework.utils.StringUtils;
import com.ev.hr.vo.AttendanceRecordImportParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import com.ev.hr.domain.AttendanceRecordDO;
import com.ev.hr.vo.AttendanceRecordPageParam;
import com.ev.hr.service.AttendanceRecordService;
import com.ev.framework.utils.R;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件名称： com.ev.hr.AttendanceRecordApiController.java</br>
 * 初始作者： ev-monitor</br>
 * 创建日期： 2020-05-18 09:36:38</br>
 * 功能说明： 考勤记录表 <br/>
 * =================================================<br/>
 * 修改记录：<br/>
 * 修改作者        日期       修改内容<br/>
 * ================================================<br/>
 * Copyright (c) 2020-2021 .All rights reserved.<br/>
 */

@Api(value = "/",tags = "考勤记录表API")
@RestController
public class AttendanceRecordApiController {

	/**
	 * 考勤记录表 服务类
	 */
	@Autowired
	private AttendanceRecordService attendanceRecordService;

	/**
	 * 方法描述: [根据条件分页查询考勤记录表.]</br>
	 * 初始作者: ev-monitor<br/>
	 * 创建日期: 2020-05-18 09:36:38<br/>
	 * 开始版本: 1.0.0<br/>
	 * =================================================<br/>
	 * 修改记录：<br/>
	 * 修改作者 日期 修改内容<br/>
	 * ================================================<br/>
	 *
	 * @param pageParam 分页参数
	 * @return R 响应对象
	 */
	@EvApiByToken(value = "/apis/attendanceRecord/pageList", method = RequestMethod.POST, apiTitle = "根据条件分页查询考勤记录表")
	@ApiOperation(value = "根据条件分页查询考勤记录表", produces = MediaType.APPLICATION_JSON_VALUE)
	public R pageList(@Valid @RequestBody @ApiParam("考勤记录表分页列表参数对象") AttendanceRecordPageParam pageParam) {
		return R.ok(this.attendanceRecordService.pageList(pageParam));
	}

	/**
	 * 方法描述: [根据id获取考勤记录表.]</br>
	 * 初始作者: ev-monitor<br/>
	 * 创建日期: 2020-05-18 09:36:38<br/>
	 * 开始版本: 1.0.0<br/>
	 * =================================================<br/>
	 * 修改记录：<br/>
	 * 修改作者 日期 修改内容<br/>
	 * ================================================<br/>
	 *
	 * @param id 主键
	 * @return R 响应对象
	 */
	@EvApiByToken(value = "/apis/attendanceRecord/detail/{id}", method = RequestMethod.GET, apiTitle = "根据id获取考勤记录表")
	@ApiOperation("根据id获取考勤记录表")
	public R detail(@PathVariable("id") @ApiParam("id") Long id) {
		return R.ok(this.attendanceRecordService.getById(id));
	}

	/**
	 * 方法描述: [批量删除]</br>
	 * 初始作者: ev-monitor<br/>
	 * 创建日期: 2020-05-18 09:36:38<br/>
	 * 开始版本: 1.0.0<br/>
	 * =================================================<br/>
	 * 修改记录：<br/>
	 * 修改作者 日期 修改内容<br/>
	 * ================================================<br/>
	 *
	 * @param ids ID组
	 * @return R 响应对象
	 */
	@EvApiByToken(value = "/apis/attendanceRecord/batchRemove", method = RequestMethod.POST, apiTitle = "批量删除")
	@ApiOperation(value = "批量删除", notes = "批量删除", produces = MediaType.APPLICATION_JSON_VALUE)
	@Transactional(rollbackFor = Exception.class)
	public R batchRemove(@RequestBody @ApiParam("批量删除") List<Long> ids){
		Long[] idsToLong = ids.toArray(new Long[0]);
		return this.attendanceRecordService.batchRemove(idsToLong)>0?R.ok():R.error();
	}

	/**
	 * 方法描述: [保存考勤记录表.]</br>
	 * 初始作者: ev-monitor<br/>
	 * 创建日期: 2020-05-18 09:36:38<br/>
	 * 开始版本: 1.0.0<br/>
	 * =================================================<br/>
	 * 修改记录：<br/>
	 * 修改作者 日期 修改内容<br/>
	 * ================================================<br/>
	 *
	 * @param saveParam 考勤记录表参数
	 * @return R 响应对象
	 */
	@Transactional(rollbackFor = Exception.class)
	@EvApiByToken(value = "/apis/attendanceRecord/save", method = RequestMethod.POST, apiTitle = "保存考勤记录表")
	@ApiOperation("保存考勤记录表")
	public R save(@Valid @RequestBody @ApiParam("保存考勤记录表对象") AttendanceRecordDO saveParam){
		return this.attendanceRecordService.saveAndVerify(saveParam);
	}

	@Transactional(rollbackFor = Exception.class)
	@EvApiByToken(value = "/apis/attendanceRecord/import", method = RequestMethod.POST, apiTitle = "导入考勤记录")
	@ApiOperation("导入考勤记录")
	public R importAttanceRecord(@ApiParam(value = "文件信息", required = true) @RequestParam("file") MultipartFile file, HttpServletResponse respons){
		return attendanceRecordService.importRecord(file);
	}
	
}
